package com.wanshi.member.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wanshi.member.base.Page;
import com.wanshi.member.base.Result;
import com.wanshi.member.entity.Goods;
import com.wanshi.member.entity.Member;
import com.wanshi.member.mapper.GoodsMapper;
import com.wanshi.member.req.GoodsREQ;
import com.wanshi.member.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品信息表 服务实现类
 * </p>
 *
 * @author 顽石教育-www.wanshi.com
 * @since 2021-05-08
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public Result update(int id, Goods goods) {
        if(goods.getId() == null) {
            goods.setId(id);
        }

        int i = baseMapper.updateById(goods);
        if(i < 1){
            return Result.error("修改会员信息失败");
        }



        return Result.ok();
    }

    @Override
    public Result search(long page, long size, GoodsREQ req) {
       IPage<Goods> p = new Page<>(page ,size);
        IPage<Goods> data = goodsMapper.findByCondPage(p,req);
        return Result.ok(data);
    }

    @Override
    public Goods findById(int id) {
        return goodsMapper.findById(id);
    }
}
